package thunderbirdgtd.tests;

import static org.junit.Assert.*;

import java.util.Date;
import java.util.LinkedList;

import org.junit.Test;

import thunderbirdgtd.entities.Action;
import thunderbirdgtd.entities.Project;
import thunderbirdgtd.entities.Tag;



public class ActionTest {
	
	
	@Test
	public void testActionIdSequence(){
		Action o = new Action("teste1");
		Action p = new Action("teste2");
		
		assertEquals(1, (p.getId()-o.getId()));
		
	}
	
	@Test
	public void testTagLoadIds(){
		Action o = new Action("test1", new Date(1995,11,5), 5);
		Action p = new Action("test3", new Date(2004,3,12), 2);
		Action n = new Action("test2");
		
		assertEquals(6, n.getId());
	}
	
	@Test
	public void testActionName() {
		Action p = new Action("test3", new Date(2004,3,12), 2);
		Action n = new Action("test2");
		assertEquals("test3", p.getName());
		assertEquals("test2", n.getName());
	}
	
	@Test
	public void testActionCreationDate() {
		Action p = new Action("test3", new Date(2004,3,12), 2);
		Action n = new Action("test2");
		assertEquals(new Date(2004,3,12), p.getCreationDate());
		assertEquals(new Date(), n.getCreationDate());
	}
	
	@Test
	public void testActionSetName() {
		Action p = new Action("test3");
		p.setName("test4");
		assertEquals("test4", p.getName());
	}
	
	@Test
	public void testeActionAddParentProject(){
		Project parent_project = new Project("processo_pai");
		Action o = new Action("test");
		
		o.setParentProject(parent_project);
		
		assertEquals(parent_project, o.getParentProject());
		
	}
	
	@Test
	public void testSearchAction() {
		
		LinkedList<Action> ll=new LinkedList<Action>();
		ll.add(new Action("test"));
		ll.add(new Action("test1"));
		ll.add(new Action("test2"));
		Action o=new Action("test_that_passes");
		ll.add(o);
		
		try {
			assertEquals(o,Action.searchActionInLinkedList("test_that_passes", ll));
			assertEquals(null,Action.searchActionInLinkedList("wqertyu",ll));
		} catch (Exception e) {
			fail("failed");
		}
		
		try {
			Action.searchActionInLinkedList(null,null);
			fail("test not passed"); 
		} catch (Exception e) {
			//all fine
		}
		
	}
	
	
	


}
